import 'dart:ffi';

import 'package:ble_measure_plugin/model/yuwell_pressure_model.dart';

import '../ble_measure_plugin.dart';
import 'base_device_model.dart';

class SannuoPressureDeviceModel extends BaseDeviceMeasureModel{

  @override
  String get serviceUuid => "0000fc00-0000-1000-8000-00805f9b34fb";

  @override
  String get characteristicWriteable => "0000fca1-0000-1000-8000-00805f9b34fb";

  @override
  String get characteristicReadable => "0000fca1-0000-1000-8000-00805f9b34fb";

  EventHandlerMap<YuwellPressureModel>? _pressureResultHandler;

  void addListener({
    EventHandlerMap<YuwellPressureModel>? resultListener,
  }) {
    _pressureResultHandler = resultListener;
  }

  var model = YuwellPressureModel();
  var hasSendResult = false;

  @override
  void onReceiveData(List<String> data) {
    if(data[1]=="0B"&&data[2]=="B8"){
      ///测量结果
      model.irregularPulse = int.parse(data[3]).toString();
      model.highPressure = int.parse(data[4],radix: 16).toString();
      model.lowPressure = int.parse(data[5],radix: 16).toString();
      model.pulse = int.parse(data[6],radix: 16).toString();
      print(model.highPressure);
      if(_pressureResultHandler!=null){
        _pressureResultHandler!(model);
      }
    }
  }

}